package com.hz.ruoyiquality.controller;


import com.hz.rouyigonggong.domain.basedomain.BaseDomain;
import com.hz.ruoyiquality.domain.LgQuality;
import com.hz.ruoyiquality.domain.dto.LgQualityStatus;
import com.hz.ruoyiquality.service.LgQualityOrderService;
import com.hz.ruoyiquality.service.LgQualityStatusService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author gj
 * @version 1.0
 * @date 2025/3/3 14:04
 */
@RestController
@RequestMapping("/outQuality")
public class LgQualityStatusController extends BaseController {
    @Autowired
    private LgQualityStatusService lgQualityStatusService;

    @Autowired
    private LgQualityOrderService lgQualityOrderService;

    /**
     * 根据id获取详细信息
     */
    @RequiresPermissions("quality:outQuality:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Integer id)
    {
        return success(lgQualityStatusService.selectLgQualityById(id));
    }

    /**
     * 根据 ID 查询订单详情（回显）
     */
    @GetMapping(value = "/getOrderInfo")
    public AjaxResult getOrderById(@RequestParam Integer orderNo) {
        return success(lgQualityOrderService.selectPendingOrderById(orderNo));
    }
    /**
     * 获取质检员列表
     */
    @RequiresPermissions("quality:outQuality:list")
    @GetMapping("/list")
    public TableDataInfo list(LgQualityStatus lgQualityStatus)
    {
        lgQualityStatus.setCreateBy(String.valueOf(BaseDomain.getUserId()));


        startPage();
        List<LgQualityStatus> list = lgQualityStatusService.selectLgQualityList(lgQualityStatus);

        return getDataTable(list);
    }

    /**
     * 表格导出质检员
     */

    @Log(title = "质检员导出数据管理", businessType = BusinessType.EXPORT)
    @RequiresPermissions("quality:outQuality:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, LgQualityStatus lgQualityStatus)
    {
        List<LgQualityStatus> list = lgQualityStatusService.selectLgQualityList(lgQualityStatus);
        ExcelUtil<LgQualityStatus> util = new ExcelUtil<LgQualityStatus>(LgQualityStatus.class);
        util.exportExcel(response, list, "质检员数据");
    }



    /**
     * 获取指定质检员的已检订单列表（inspection_status = 1）
     * @param inspectorId 质检员 ID
     * @return 分页后的订单数据
     */
    @GetMapping("/listByQualityManWan")
    public TableDataInfo getCheckedOrdersByInspector(@RequestParam Integer inspectorId) {
        startPage();

        // 查询符合条件的订单
        List<LgQualityStatus> orders = lgQualityStatusService.getQualityStatusByInspectorApp(inspectorId);

        return getDataTable(orders);
    }
    @GetMapping("/listByQualityManWan1")
    public TableDataInfo getCheckedOrdersByInspector1(@RequestParam Integer inspectorId) {


        // 查询符合条件的订单
        List<LgQualityStatus> orders = lgQualityStatusService.getQualityStatusByInspectorApp(inspectorId);

        return getDataTable(orders);
    }

}
